package chapter7;
import static utility.Print.*;

/**
 * Exercise 1: (2) Create a simple class. Inside a second class, define a
 * reference to an object of the first class. Use lazy initialization to
 * instantiate this object.
 * 
 */

class SimpleClass {
	String text;

	public SimpleClass(String text) {
	    super();
	    this.text = text;
    }

	public void concatenateText(String text) {
	    this.text = this.text + text;
    }

	@Override
    public String toString() {
	    return "SimpleClass [text=" + text + "]";
    }
	
}

class ComplexClass {
	SimpleClass sc;
	public void addText(String s) {
		if (sc == null) {
			sc = new SimpleClass(s);
		}
		else {
			sc.concatenateText(s);
		}
	}
	@Override
    public String toString() {
	    return "ComplexClass [sc=" + sc + "]";
    }
	
}

public class Exercise1 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		ComplexClass c = new ComplexClass();
		
		c.addText("initial text \n");
		c.addText("second text \n");
		c.addText("third text \n");
		
		print(c.toString());
		

	}

}
